<?php 
include_once("./com.php");
error_reporting(E_ALL^E_NOTICE^E_WARNING);
date_default_timezone_set("PRC");
//两表关联遍历商品库
$rem="select pr.*,pc.pc_name from pc_fenlei pc,product pr where pr.pc_cid=pc.pc_cid";

$rs=mysql_query($sql);
$info=[];
$totalRows=mysql_num_rows($rs);
$pageRows=4;
$totalPage=ceil($totalRows / $pageRows);
$page=isset($_GET['page'])?$_GET['page']:1;
if ($page<=0||$page>$totalPage||!is_numeric($page)) {
  $page=1;
}
//5.处理limit查询的第一个参数，分页计算公式
$limitstart=$pageRows * ($page-1);
//6.组装sql语句
$sql="SELECT * FROM tk_admin order by admin_id desc limit {$limitstart},{$pageRows}";
//7.获取分页数据
$re=mysql_query($sql);
$info=[];
if(mysql_num_rows($re)>0){
  while($arr=mysql_fetch_assoc($re)){
    $info[]=$arr;
  }
}


$ser=mysql_query($rem);
while($res=mysql_fetch_assoc($ser)){
    $products[]=$res;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>商品管理</title>
<base target="_self">
<link rel="stylesheet" type="text/css" href="skin/css/base.css" />
<link rel="stylesheet" type="text/css" href="skin/css/main.css" />
</head>
<body leftmargin="8" topmargin='8'>
<table width="98%" align="center" border="0" cellpadding="3" cellspacing="1" bgcolor="#CBD8AC" style="margin-bottom:8px;margin-top:8px;">
  <tr>
    <td background="skin/images/frame/wbg.gif" bgcolor="#EEF4EA" class='title' colspan="2"><span><img src='skin/images/frame/arr3.gif' style='margin-right:10px;'>产品列表</span></td>
  </tr>
    <tr bgcolor="#FFFFFF">
       <td colspan="2">
            <table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CFCFCF" align="center" style="margin-top:8px">
            <tr align="center" bgcolor="#FBFCE2" height="25">
                <th width="3%">编号</th>
                <th width="10%">产品序列号</th>
                <th width="10%">商品名称</th>
                <th width="10%">商品图片</th>
                <th width="10%">商品分类</th>
                <th width="10%">商品价格</th>
                <th width="10%">优惠价格</th>
                <th width="10%">商品产地</th>
                <th width="10%">是否展示</th>
                <th width="10%">操作</th>
            </tr>
            <?php foreach ($products as $value) { ?>
            <tr align='center' bgcolor="#FFFFFF" height="26" align="center" onMouseMove="javascript:this.bgColor='#FCFDEE';" onMouseOut="javascript:this.bgColor='#FFFFFF';">
                <td><?= $value['pid']?></td>
                <td><?= $value['pnums']?></td>
                <td><?= $value['pname']?></td>
                <td><img src="../uploads/<?= $value['pimg'] ?>" width="20px"></td>
                <td><?= $value['pc_name'] ?></td>
                <td><?= $value['price']?></td>
                <td><?= $value['sprice']?></td>
                <td><?= $value['addr']?></td>
                <td>
                <?php if($value['ifshow']==1){  ?>
                        上架
                <?php   }elseif($value['ifshow']==0){  ?>
                        下架
                <?php   } ?>        
                </td>
                <td width="10%">
                    <a href="product_edit.php?pid=<?= $value['pid']?>"><img src='./skin/images/frame/trun.gif' title="编辑" alt="编辑" onClick="QuickEdit(179, event, this);" style='cursor:pointer' border='0' width='16' height='16' /></a>

                    <a href="product_del.php?pid=<?= $value['pid'] ?>"><img src='./skin/images/frame/gtk-del.png' title="删除" alt="删除" onClick="editArc(179);" style='cursor:pointer' border='0' width='16' height='16' /></a>         
                </td> 
            </tr>
            <?php }?>
        </table>

<tr align="right" bgcolor="#F9FCEF">
        <td height="36" colspan="10" align="center">
        <div class="pagelistbox" style="font-size: 18px;">
          <span>共<?php echo $totalpage;?> 1页/<?php echo $totalRows;?>条记录</span>
          <span class="indexpage">
            <a href="?page=1">首页</a>
            <a class="prevPage" href="?page=<?php echo $page-1?>">上页</a>
          </span>

            <?php for($i=1;$i<= $totalpage;$i++):?>
              <?php if($i ==$page ):?>
              <strong><?php echo $i;?></strong>

              <?php else:?>
              <a href="?page=<?php echo $i;?>"><?php echo $i;?></a>

            <?php endif;?>
            <?php endfor;?> 
              <a class="nextpage" href="?page=<?php echo $page+1;?>">下页</a>
              <a class="endpage" href="?page=<?php echo $totalPage;?>">末页</a>
        </div>
      </td>
      </tr>


        
    </td>
  </tr>
  </tr>
</table>
</body>
</html>